package cn.edu.scau.cmi.yanweijie.combination;

import java.util.ArrayList;
import java.util.List;


public class Organization implements Component{
	
	public String Name="源组织";
	
	public String Type="组织";
	
	public Integer generation = 0;
	
	List<Person> perList = new ArrayList<Person>();
	List<Organization> orgList = new ArrayList<Organization>();
	
	public String FatherName = null;
	
	public List<Person> getPerList() {
		return perList;
	}

	public void setPerList(List<Person> perList) {
		this.perList = perList;
	}

	public List<Organization> getOrgList() {
		return orgList;
	}

	public void setOrgList(List<Organization> orgList) {
		this.orgList = orgList;
	}

	public String getFatherName() {
		return FatherName;
	}

	public void setFatherName(String fatherName) {
		FatherName = fatherName;
	}

	public Organization() {
		
	}
	
	public Organization(String name) {
		this.Name = name;
	}
	
	
	
	public void addPerson(Person person) {
		perList.add(person);
		person.generation=this.generation+1;
		person.FatherName = this.Name;
	}

	public void addOrganization(Organization organization) {
		orgList.add(organization);
		organization.generation=this.generation+1;
		organization.FatherName = this.Name;
	}
	
	public void remove(String hostName,String nodeName) {
		if (Name.equalsIgnoreCase(hostName)) {
			System.out.println("try to delete");
			for (Person person : this.perList) {
				//System.out.println(person.getName()+"  "+nodeName);
				if (person.getName().equalsIgnoreCase(nodeName)) {
					perList.remove(person);
					person.FatherName=null;
					return ;
				}
			}
			for (Organization organization : orgList) {
				//System.out.println(organization.getName()+"  "+nodeName);
				if (organization.getName().equalsIgnoreCase(nodeName)) {
					orgList.remove(organization);
					organization.FatherName=null;
					return ;
				}
			}
		}
	}
	
	public void removeAll(String hostName) {
		if (Name.equalsIgnoreCase(hostName)) {
			for (Person person : perList) {
					person.FatherName=null;
				
			}
			for (Organization organization : orgList) {
					organization.FatherName=null;
			}
		}
	}

	public String getName() {
		return Name;
	}

	public void setName(String name) {
		Name = name;
	}

	public String getType() {
		return Type;
	}

	public void setType(String type) {
		Type = type;
	}

	public Integer getGeneration() {
		return generation;
	}

	public void setGeneration(Integer generation) {
		this.generation = generation;
	}


	@Override
	public String toString() {
		return "Organization [Name=" + Name + ", Type=" + Type + ", generation=" + generation + ", orgList=" + orgList
				+ "]";
	}

	
	
}
